<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
	+ request.getServerName() + ":" + request.getServerPort()
	+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<link rel="stylesheet" style="text/css" href="resource/css/main.css" />
<title>spring from test</title>

<script type="text/javascript" src="resource/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
	saveUserInfo = function() {
		$("#myForm").submit();
	}
	updateUserInfo = function(userId) {
		$.ajax({
			type : "POST",
			url : "index/updateUser.htm",
			data : {
				"userId" : userId
			},
			dataType : "json",
			success : function(data) {
				alert(data);
			},
			error : function() {
				alert("请求失败<_>");
			}
		});
	}

	ajaxToProperty = function() {
		$.ajax({
			type : "json",
			url : "index/ajaxToProperty.htm",
			dataType : "json",
			success : function(data) {
				alert(data.userId);
			},
			error : function() {
				alert("请求失败<_>");
			}
		});
	}

	ajaxToOne = function() {
		$.ajax({
			type : "json",
			url : "index/ajaxToOne.htm",
			dataType : "json",
			success : function(data) {
				alert(data.name);
			},
			error : function() {
				alert("请求失败<_>");
			}
		});
	}

	ajaxToMore = function() {
		$.ajax({
			type : "json",
			url : "index/ajaxToMore.htm",
			dataType : "json",
			success : function(data) {
				for (var i = 0; i < data.length; i++) {
					alert(data[i].name);
				}
			},
			error : function() {
				alert("请求失败<_>");
			}
		});
	}
	ajaxToMap = function() {
		$.ajax({
			type : "json",
			url : "index/ajaxToMap.htm",
			dataType : "json",
			success : function(data) {
				alert(data.user.length);
			},
			error : function() {
				alert("请求失败<_>");
			}
		});
	}
</script>
<style type="text/css">
.errors {
	color: red;
}
</style>
</head>
<body>
	<s:debug></s:debug>
	<div class="main">
		<button onclick="ajaxToProperty()">加载单个属性</button>
		<button onclick="ajaxToOne()">加载更多(单个对象)</button>
		<button onclick="ajaxToMore()">加载更多(list对象)</button>
		<button onclick="ajaxToMap()">加载更多(map对象)</button>
		<!-- 			<ul class="content"> -->
		<!-- 				<li><s:property value="#user.id" /></li> -->
		<!-- 				<li><s:property value="#user.name" /></li> -->
		<!-- 				<li><s:property value="#user.password" /></li> -->
		<!-- 				<li class="ljgm"><a class="update" href="javascript:void(0)" -->
		<!-- 					onclick="updateUserInfo('<s:property value='#user.id'/>')">修改</a></li> -->
		<!-- 			</ul> -->
		<sf:form method="post" id="myForm" modelAttribute="userInfo"
			action="index/saveInfo.htm" enctype="multipart/form-data">
			<sf:errors path="errors" />
			<table style="margin: 0px auto;">
				<tr>
					<td>Court Name</td>
					<td><input type="text" name="user.name"></td>
					<%-- 					<td><sf:input path="name"/></td> --%>
					<td><sf:errors path="name" class="errors" />
				</tr>
				<tr>
					<td>pass</td>
					<td><sf:input path="password" /></td>
					<td><sf:errors path="password" class="errors" />
				</tr>
				<tr>
					<td>image</td>
					<td><input type="file" name="image" /></td>
				</tr>
				<tr>
					<td></td>
				</tr>
				<tr>
					<td colspan="3"><span class="ljgm"> <a class="update"
							href="javascript:void(0)" onclick="saveUserInfo()">提交</a>
					</span></td>
				</tr>
			</table>
		</sf:form>
	</div>
	<div class="main_left">
		<ul>
			<li>登陆</li>
		</ul>

	</div>
</body>
</html>
